package com.op.core.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.op.constants.NumberConstant;
import com.op.core.entity.File;
import com.op.core.mapper.FileMapper;
import com.op.core.service.FileService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * (File)表服务实现类
 *
 * @author 孤焰
 * @since 2021-10-07 09:52:18
 */
@Service("fileService")
public class FileServiceImpl extends ServiceImpl<FileMapper, File> implements FileService {
    @Resource
    FileMapper fileMapper;

    @Override
    public boolean isExist(File file) {
        if (!CollectionUtils.isEmpty(fileMapper.selectList(new QueryWrapper<>(file)))) {
            return true;
        }
        return false;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean logicDelBatchById(List<Long> idList) {
        for (Long id : idList) {
            File file = new File();
            file.setId(id);
            file.setStatus(NumberConstant.DISABLE);
            if (fileMapper.updateById(file) <= 0) {
                throw new RuntimeException("部分删除失败");
            }
        }
        return true;
    }
}

